package cn.edu.lingnan.services;

import cn.edu.lingnan.dao.ScoreMapper;
import cn.edu.lingnan.pojo.Score;
import cn.edu.lingnan.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;


import java.util.List;
import java.util.Map;
import java.util.Vector;


public class ScoreServiceMysqlImpl implements ScoreService {
        @Override
        public Vector<Score> findAllScore() {
            Vector<Score> vector = null;
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            vector = scoreMapper.findAllScore();
            return vector;
        }

        @Override
        public List<Score> findScoreById(String cid) {
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            List<Score> scores = scoreMapper.findScoreById(cid);
            return scores;
        }

        //-------------------------------------------------------------------------------

        @Override
        public List<Score> findScoreByNameUseLike(String cname) {
            List<Score> scores = null;
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            scores = scoreMapper.findScoreByNameUseLike(cname);
            sqlSession.close();
            return scores;
        }

        @Override
        public int insertScore(Score score) {
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            int i = scoreMapper.insertScore(score);
            sqlSession.commit();
            return i;
        }

        @Override
        public int updateScore(Score score) {
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            int i = scoreMapper.updateScore(score);
            sqlSession.commit();
            return i;
        }

        @Override
        public int updateScorePassword(Map map) {
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            int i = scoreMapper.updateScorePassword(map);
            sqlSession.commit();
            return i;
        }

        @Override
        public int deleteScore(Map map) {
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            int i = scoreMapper.deleteScore(map);
            sqlSession.commit();
            return i;
        }

        @Override
        public List<Score> findScoreUseIf(Map map) {
            List<Score> list = null;
            SqlSession sqlSession = MybatisUtil.getSqlSession();
            ScoreMapper scoreMapper = sqlSession.getMapper(ScoreMapper.class);
            list = scoreMapper.findScoreUseIf(map);
            return list;
        }
    }


